import { root } from "../apiRoot";
import { defHttp } from '@/utils/http';
import { IQuery, IResData } from "../types";
import { AddCircleData, AuditCircleJoinData, CircleDetailResult, CircleFileListResult, CircleIdentityListResult, CircleJoinApplyListResult, CircleListResult, CircleMemberDetailResult, CircleMemberListResult, FriendApplyDetailResult, FriendApplyListResult, FriendDetailResult, FriendListResult, LabelFriendListResult, LabelListResult, SaveFileUploadPermData, UpdateCircleInfoData, UpdateCircleMemberInfoData } from "./types";
import { FileUploadPolicyEnum, ReviewStatusEnum } from "@/enums/PublicEnum";
import { FileAuthInfo, KnowledgeBaseFileListResult } from "../knowledgeBase/types";

const Api = {
  friendList: root + 'bot/friend/list',
  circleList: root + 'circle/list',
  labelFriendList: root + 'bot/friend/label/friendList',

  labelList: root + 'bot/label/list',
  addOrUpdateLabel: root + 'bot/label/addOrUpdate',
  deleteLabel: root + 'bot/label/delete',

  queryBecomeFriends: root + 'bot/friend/queryBecomeFriends',

  inviteReview: root + 'bot/friend/inviteReview',
  friendApplyList: root + 'bot/friend/applyList',
  friendApplyDetail: root + 'bot/friend/applyDetail',
  circleJoinApplyList: root + 'circle/reviewList',

  applyJoinCircle: root + 'circle/applyJoin',
  circleApplyDetail: root + 'circle/reviewDetail',
  auditCircleJoin: root + 'circle/reviewJoin',


  auditFriendApply: root + 'bot/friend/review',
  friendDetail: root + 'bot/friend/detail',
  addFriendLabel: root + 'bot/friend/label/add',
  deleteFriendLabel: root + 'bot/friend/label/remove',
  addCircle: root + 'circle/add',
  aiSelectFriendList: root + 'bot/file/selectFriendList',
  aiSelectCircleList: root + 'circle/selectList',
  appBotCircleDetail: root + 'app_bot/getCircleDetail',
  circleSettingDetail: root + 'circle/setDetail',
  updateCircleInfo: root + 'circle/update',
  dissolveCircle: root + 'circle/dissolve',
  circleMemberList: root + 'circle/memberList',
  circleFileList: root + 'circle/fileList',
  selectCircleMemberList: root + 'circle/selectMemberList',
  saveFileUploadPerm: root + 'circle/saveFileUploadPerm',
  exitCircle: root + 'circle/exit',

  circleAdminList: root + 'circle/selectAdminList',
  addCircleAdmin: root + 'circle/addAdmins',
  removeCircleAdmin: root + 'circle/removeAdmin',

  circleMemberDetail: root + 'circle/memberDetail',
  circleIdentityList: root + 'circle/identityList',
  circleDeleteCircleIdentity: root + 'circle/identityDelete',
  circleUpdateCircleIdentity: root + 'circle/identityUpdate',

  createCircleIdentity: root + 'circle/identitySave',
  updateCircleMemberInfo: root + 'circle/updateMemberInfo',
  circleSelectableFileList: root + 'circle/selectableFileList',
  addCircleSharedFile: root + 'circle/addSharedFile',

  removeCircleSharedFile: root + 'circle/removeFile',
  setCircleFilePerm: root + 'circle/saveFileCallPerm',

  removeCircleMember: root + 'circle/removeCircleMember',

  transferSuperAdmin: root + 'circle/transferSuperAdmin'
}

/**
 * @description 好友列表
 * @date 07/03/2025
 * @export
 * @param {IQuery} data
 */
export function friendList(data: { keyWord?: string } & IQuery) {
  return defHttp.post<IResData<FriendListResult>>({
    url: Api.friendList,
    data
  })
}

/**
 * @description 圈子列表
 * @date 10/03/2025
 * @export
 */
export function circleList(data: { keyWord?: string } & IQuery) {
  return defHttp.post<IResData<CircleListResult>>({
    url: Api.circleList,
    data
  })
}

/**
 * @description 标签列表
 * @date 07/03/2025
 * @export
 */
export function labelList(data: { keyWord?: string }) {
  return defHttp.post<LabelListResult[]>({
    url: Api.labelList,
    data
  })
}

/**
 * @description 标签成员列表
 * @date 10/03/2025
 * @export
 */
export function labelFriendList(data: { id: number, keyWord?: string }) {
  return defHttp.post<LabelFriendListResult[]>({
    url: Api.labelFriendList,
    data
  })
}

/**
 * @description 新增或更新标签
 * @date 07/03/2025
 * @export
 */
export function addOrUpdateLabel(data: { id?: number, label: string }) {
  return defHttp.post({
    url: Api.addOrUpdateLabel,
    data
  })
}

/**
 * @description 删除标签
 * @date 18/03/2025
 * @export
 */
export function deleteLabel(id: number) {
  return defHttp.post({
    url: Api.deleteLabel + `/${id}`,
  })
}

/**
 * @description 查询是否已成为好友
 * @date 08/03/2025
 * @export
 * @param {string} uuid
 */
export function queryBecomeFriends(uuid: string) {
  return defHttp.post({
    url: Api.queryBecomeFriends,
    data: {
      uuid
    }
  })
}

/**
 * @description 同意成为好友
 * @date 08/03/2025
 * @export
 * @param {{ uuid: string, currentBotId: number }} data
 */
export function agreeInvite(data: { uuid: string, currentBotId: number }) {
  return defHttp.post({
    url: Api.inviteReview,
    data
  })
}

/**
 * @description 好友申请列表
 * @date 07/03/2025
 * @export
 */
export function friendApplyList(data: IQuery) {
  return defHttp.post<IResData<FriendApplyListResult[]>>({
    url: Api.friendApplyList,
    data
  })
}

/**
 * @description 好友申请详情
 * @date 08/03/2025
 * @export
 */
export function friendApplyDetail(data: { id: number }) {
  return defHttp.post<FriendApplyDetailResult>({
    url: Api.friendApplyDetail,
    data
  })
}

/**
 * @description 圈子加入申请列表
 * @date 13/03/2025
 * @export
 * @param {IQuery} data
 */
export function circleJoinApplyList(data: IQuery) {
  return defHttp.post<IResData<CircleJoinApplyListResult[]>>({
    url: Api.circleJoinApplyList,
    data
  })
}

/**
 * @description 审核好友申请
 * @date 08/03/2025
 * @export
 */
export function auditFriendApply(data: { id: number, reviewStatus: ReviewStatusEnum }) {
  return defHttp.post({
    url: Api.auditFriendApply,
    data
  })
}

/**
 * @description 好友详情
 * @date 09/03/2025
 * @export
 */
export function friendDetail(data: { id: number }) {
  return defHttp.post<FriendDetailResult>({
    url: Api.friendDetail,
    data
  })
}

/**
 * @description 添加好友标签
 * @date 10/03/2025
 * @export
 * @param {{ botFriendId: number, botLabelIdList: number[] }} data
 */
export function addFriendLabel(data: { botFriendId: number, botLabelIdList: number[] }) {
  return defHttp.post({
    url: Api.addFriendLabel,
    data
  })
}

/**
 * @description 删除好友标签
 * @date 10/03/2025
 * @export
 * @param {{ botFriendId: number, botLabelId: number }} data
 */
export function deleteFriendLabel(data: { botFriendId: number, botLabelId: number }) {
  return defHttp.post({
    url: Api.deleteFriendLabel,
    data
  })
}

/**
 * @description 新增或更新圈子
 * @date 09/03/2025
 * @export
 */
export function addCircle(data: AddCircleData) {
  return defHttp.post<string>({
    url: Api.addCircle,
    data
  })
}


/**
 * @description 获取好友列表
 * @date 09/03/2025
 * @export
 */
export function aiSelectFriendList(data: { keyWord?: string }) {
  return defHttp.post<FriendListResult[]>({
    url: Api.aiSelectFriendList,
    data,
  });
}

/**
 * @description 获取圈子列表
 * @date 10/03/2025
 * @export
 */
export function aiSelectCircleList(data: { keyWord?: string }) {
  return defHttp.post<CircleListResult[]>({
    url: Api.aiSelectCircleList,
    data,
  });
}

/**
 * @description 获取对外圈子详情
 * @date 11/03/2025
 * @export
 * @param {{ uuid: string }} data
 */
export function appBotCircleDetail(data: { uuid: string }) {
  return defHttp.post<CircleDetailResult>({
    url: Api.appBotCircleDetail,
    data
  })
}

/**
 * @description 圈子设置详情(对内)
 * @date 11/03/2025
 * @export
 * @param {{ uuid: string }} data
 */
export function circleSettingDetail(data: { uuid: string }) {
  return defHttp.post<CircleDetailResult>({
    url: Api.circleSettingDetail,
    data
  })
}

/**
 * @description 更新圈子信息
 * @date 11/03/2025
 * @export
 * @param {UpdateCircleInfoData} data
 */
export function updateCircleInfo(data: UpdateCircleInfoData) {
  return defHttp.post({
    url: Api.updateCircleInfo,
    data
  })
}

/**
 * @description 解散圈子
 * @date 11/03/2025
 * @export
 */
export function dissolveCircle(data: { id: number }) {
  return defHttp.post({
    url: Api.dissolveCircle,
    data
  })
}

/**
 * @description 退出圈子
 * @date 11/03/2025
 * @export
 * @param {{ id: number }} data
 */
export function exitCircle(data: { id: number }) {
  return defHttp.post({
    url: Api.exitCircle,
    data
  })
}

/**
 * @description 圈子成员列表
 * @date 11/03/2025
 * @export
 */
export function circleMemberList(data: { id: number } & IQuery) {
  return defHttp.post<CircleMemberListResult[]>({
    url: Api.circleMemberList,
    data
  })
}

/**
 * @description 选择圈子成员列表
 * @date 11/03/2025
 * @export
 */
export function selectCircleMemberList(data: { id: number, keyWord?: string }) {
  return defHttp.post<CircleMemberListResult[]>({
    url: Api.selectCircleMemberList,
    data
  })
}

/**
 * @description 圈子文件上传限制的已选成员列表
 * @date 11/03/2025
 * @export
 */
export function circleFileUploadLimitMemberList(data: { id: number }) {
  return defHttp.post<FileAuthInfo[]>({
    url: root + 'circle/selectCircleFileMember',
    data
  })
}

/**
 * @description 圈子文件权限的已选成员列表
 * @date 12/03/2025
 * @export
 */
export function circleFilePermMemberList(data: { circleFileId: number }) {
  return defHttp.post<FileAuthInfo[]>({
    url: root + 'circle/selectCircleFileMember',
    data
  })
}

/**
 * @description 保存圈子文件上传权限
 * @date 11/03/2025
 * @export
 */
export function saveFileUploadPerm(data: SaveFileUploadPermData) {
  return defHttp.post({
    url: Api.saveFileUploadPerm,
    data
  })
}

/**
 * @description 圈子管理员列表
 * @date 12/03/2025
 * @export
 * @param {{ id: number }} data
 */
export function circleAdminList(data: { id: number }) {
  return defHttp.post<CircleMemberListResult[]>({
    url: Api.circleAdminList,
    data
  })
}

/**
 * @description 批量添加圈子管理员
 * @date 11/03/2025
 * @export
 */
export function addCircleAdmin(data: { circleId: number, memberIds: number[] }) {
  return defHttp.post({
    url: Api.addCircleAdmin,
    data
  })
}

/**
 * @description 删除圈子管理员
 * @date 11/03/2025
 * @export
 */
export function removeCircleAdmin(data: { id: number }) {
  return defHttp.post({
    url: Api.removeCircleAdmin,
    data
  })
}

/**
 * @description 圈子成员详情
 * @date 12/03/2025
 * @export
 * @param {{ id: number }} data
 */
export function circleMemberDetail(data: { memberId: number }) {
  return defHttp.post<CircleMemberDetailResult>({
    url: Api.circleMemberDetail,
    data
  })
}

/**
 * @description 圈子身份列表
 * @date 12/03/2025
 * @export
 * @param {{ id: number, keyWord?: string }} data
 */
export function circleIdentityList(data: { id: number, keyWord?: string }) {
  return defHttp.post<CircleIdentityListResult[]>({
    url: Api.circleIdentityList,
    data
  })
}

/**
 * @description 删除圈子身份
 * @date 18/03/2025
 * @export
 */
export function circleDeleteCircleIdentity(data: { id: number }) {
  return defHttp.post({
    url: Api.circleDeleteCircleIdentity,
    data
  })
}

/**
 * @description 更新圈子身份
 * @date 18/03/2025
 * @export
 */
export function circleUpdateCircleIdentity(data: { id: number, name: string }) {
  return defHttp.post({
    url: Api.circleUpdateCircleIdentity,
    data
  })
}

/**
 * @description 创建圈子身份
 * @date 12/03/2025
 * @export
 */
export function createCircleIdentity(data: { circleId: number, name: string }) {
  return defHttp.post({
    url: Api.createCircleIdentity,
    data
  })
}

/**
 * @description 更新圈子成员信息
 * @date 12/03/2025
 * @export
 * @param {UpdateCircleMemberInfoData} data
 */
export function updateCircleMemberInfo(data: UpdateCircleMemberInfoData) {
  return defHttp.post({
    url: Api.updateCircleMemberInfo,
    data
  })
}

/**
 * @description 获取圈子可选知识库文件列表
 * @date 12/03/2025
 * @export
 * @param {{ circleId: number }} data
 */
export function circleSelectableFileList(data: { circleId: number } & IQuery) {
  return defHttp.post<KnowledgeBaseFileListResult[]>({
    url: Api.circleSelectableFileList,
    data
  })
}

/**
 * @description 添加圈子共享文件
 * @date 12/03/2025
 * @export
 */
export function addCircleSharedFile(data: { circleId: number, fileIds: number[] }) {
  return defHttp.post({
    url: Api.addCircleSharedFile,
    data
  })
}

/**
 * @description 圈子文件列表
 * @date 12/03/2025
 * @export
 */
export function circleFileList(data: { circleId: number } & IQuery) {
  return defHttp.post<CircleFileListResult[]>({
    url: Api.circleFileList,
    data
  })
}

/**
 * @description 删除圈子共享文件
 * @date 12/03/2025
 * @export
 * @param {{ circleFileId: number }} data
 */
export function removeCircleSharedFile(data: { circleFileId: number }) {
  return defHttp.post({
    url: Api.removeCircleSharedFile,
    data
  })
}

/**
 * @description 设置圈子文件权限
 * @date 12/03/2025
 * @export
 */
export function setCircleFilePerm(data: { circleFileId: number, fileCallPolicy: FileUploadPolicyEnum, memberIds: number[] }) {
  return defHttp.post({
    url: Api.setCircleFilePerm,
    data
  })
}


/**
 * @description 删除圈子成员
 * @date 12/03/2025
 * @export
 */
export function removeCircleMember(data: { memberId: number }) {
  return defHttp.post({
    url: Api.removeCircleMember,
    data
  })
}

/**
 * @description 申请加入圈子
 * @date 13/03/2025
 * @export
 * @param {{ circleId: number, botId: number }} data=
 */
export function applyJoinCircle(data: { circleId: number, botId: number }) {
  return defHttp.post({
    url: Api.applyJoinCircle,
    data
  })
}

/**
 * @description 圈子申请详情
 * @date 12/03/2025
 * @export
 */
export function circleApplyDetail(data: { id: number }) {
  return defHttp.post<CircleJoinApplyListResult>({
    url: Api.circleApplyDetail,
    data
  })
}


/**
 * @description 审核圈子加入申请
 * @date 13/03/2025
 * @export
 */
export function auditCircleJoin(data: AuditCircleJoinData) {
  return defHttp.post({
    url: Api.auditCircleJoin,
    data
  })
}

/**
 * @description 转移超级管理员
 * @date 19/03/2025
 * @export
 */
export function transferSuperAdmin(data: { circleId: number, toUserId: number }) {
  return defHttp.post({
    url: Api.transferSuperAdmin,
    data
  })
}

